package com.qeado.report.web;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jofc2.OFCException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.qeado.common.helper.AttributeHelper;
import com.qeado.report.service.ReportService;

@Controller
public class ReportController {
	@Autowired
	private ReportService reportService;
	
	@RequestMapping("/userCountReport.ac")
	public String userCountReport(HttpServletRequest request) {
		AttributeHelper.removeSessionAttribute(request, "T_");
		return "report/user_count_report";
	}
	
	@RequestMapping("/prodPubReport.ac")
	public String prodPubReport(HttpServletRequest request) {
		AttributeHelper.removeSessionAttribute(request, "T_");
		return "report/prod_pub_report";
	}
	
	@RequestMapping("/baikeVisitReport.ac")
	public String baikeVisitReport(HttpServletRequest request) {
		AttributeHelper.removeSessionAttribute(request, "T_");
		return "report/baike_visit_report";
	}
	
	@RequestMapping("/siteVisitReport.ac")
	public String siteVisitReport(HttpServletRequest request) {
		AttributeHelper.removeSessionAttribute(request, "T_");
		return "report/site_visit_report";
	}
	
	@RequestMapping("/createUserCountReport.ac")
	public void createUserCountReport(HttpServletRequest request, HttpServletResponse response) throws OFCException, IOException {
		String timeFrom = request.getParameter("timeFrom");
		String timeTo = request.getParameter("timeTo");
		String chart = reportService.createUserCountReport(timeFrom, timeTo);
//		request.setAttribute("timeFrom", timeFrom);
//		request.setAttribute("timeTo", timeTo);
		response.setContentType("application/json-rpc;charset=utf-8");  
        response.setHeader("Cache-Control", "no-cache");  
        response.setHeader("Expires", "0");  
        response.setHeader("Pragma", "No-cache");  
        response.getWriter().write(chart);  
	}
	
	@RequestMapping("/createProdPubReport.ac")
	public void createProdPubReport(HttpServletRequest request, HttpServletResponse response) throws OFCException, IOException {
		String timeFrom = request.getParameter("timeFrom");
		String timeTo = request.getParameter("timeTo");
		String chart = reportService.createProdPubReport(timeFrom, timeTo);
//		request.setAttribute("timeFrom", timeFrom);
//		request.setAttribute("timeTo", timeTo);
		response.setContentType("application/json-rpc;charset=utf-8");  
        response.setHeader("Cache-Control", "no-cache");  
        response.setHeader("Expires", "0");  
        response.setHeader("Pragma", "No-cache");  
        response.getWriter().write(chart);  
	}
	
	@RequestMapping("/createBaikeVisitReport.ac")
	public void createBaikeVisitReport(HttpServletRequest request, HttpServletResponse response) throws OFCException, IOException {
		String timeFrom = request.getParameter("timeFrom");
		String timeTo = request.getParameter("timeTo");
		String chart = reportService.createBaikeVisitReport(timeFrom, timeTo);
//		request.setAttribute("timeFrom", timeFrom);
//		request.setAttribute("timeTo", timeTo);
		response.setContentType("application/json-rpc;charset=utf-8");  
        response.setHeader("Cache-Control", "no-cache");  
        response.setHeader("Expires", "0");  
        response.setHeader("Pragma", "No-cache");  
        response.getWriter().write(chart); 
	}
	
	@RequestMapping("/createSiteVisitReport.ac")
	public void createSiteVisitReport(HttpServletRequest request, HttpServletResponse response) throws OFCException, IOException {
		String timeFrom = request.getParameter("timeFrom");
		String timeTo = request.getParameter("timeTo");
		String chart = reportService.createSiteVisitReport(timeFrom, timeTo);
//		request.setAttribute("timeFrom", timeFrom);
//		request.setAttribute("timeTo", timeTo);
		response.setContentType("application/json-rpc;charset=utf-8");  
        response.setHeader("Cache-Control", "no-cache");  
        response.setHeader("Expires", "0");  
        response.setHeader("Pragma", "No-cache");  
        response.getWriter().write(chart);  
	}
}
